/**
 * Created by Administrator on 2017/8/12 0012.
 */
var crypto = require('crypto'),
    fs = require('fs'),
    path = require('path'),
    pem = fs.readFileSync(path.join(__dirname, '../../../') + './server.pem'),
    key = pem.toString('ascii');

module.exports = {
    encrypt: function (text) {
        var cipher = crypto.createCipher('aes-256-cbc', key),
            crypted = cipher.update(text,'utf8','hex');
        crypted += cipher.final('hex');
        return crypted;
    },
    descrypt: function (crypted) {
        var decipher = crypto.createDecipher('aes-256-cbc', key),
            dec = decipher.update(crypted,'hex','utf8');
        try {
            dec += decipher.final('utf8');
        }catch (e){
            console.error(e);
        }
        return dec;
    }
};

